﻿using Common.Communal;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Product.API.Write.Applications.Commands.Bom;

namespace Product.API.Write.Controllers
{
    /// <summary>
    /// Bom管理API-写
    /// </summary>
    [Route("api/[controller]")]
    [ApiController]
    public class BomController : ControllerBase
    {
        /// <summary>
        /// 中介者
        /// </summary>
        private readonly IMediator mediator;

        /// <summary>
        /// 构造计划
        /// </summary>
        /// <param name="mediator">中介者</param>
        public BomController(IMediator mediator)
        {
            this.mediator = mediator;
        }

        /// <summary>
        /// Bom创建
        /// </summary>
        /// <param name="command">请求</param>
        /// <returns>返回任务</returns>
        [HttpPost("CreateBom")]
        public async Task<ApiResult<int>> CreateBom(CreateBomCommand command)
        {
            return await mediator.Send(command);
        }

        /// <summary>
        /// Bom修改
        /// </summary>
        /// <param name="command">请求</param>
        /// <returns>返回任务</returns>
        [HttpPost("UpdateBom")]
        public async Task<ApiResult<int>> UpdateBom(UpdateBomCommand command)
        {
            return await mediator.Send(command);
        }

        /// <summary>
        /// Bom删除
        /// </summary>
        /// <param name="Id">主键ID</param>
        /// <returns>返回任务</returns>
        [HttpGet("DeleteBom")]
        public async Task<ApiResult<int>> DeleteBom(int Id)
        {
            DeleteBomCommand command = new DeleteBomCommand();
            command.Id = Id;
            return await mediator.Send(command);
        }




    }
}
